<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>药品管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script type="text/javascript" src="/res/js/jquery-3.4.1.js"></script>
    <link rel="stylesheet" href="/res/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<form class="layui-form" lay-filter="component-form-group" id="search_submits" onsubmit="return false">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-useradmin-formlist" style="height: 80px">
        <div class="layui-form-item">
            <label class="layui-form-label">药品名称:</label>
            <div class="layui-input-inline">
                <input type="text" name="drugName" id="drugName" placeholder="请输入药品名称" autocomplete="off"
                       class="layui-input">

            </div>
            <input type="hidden" id="excelDataVO">
            <div class="layui-input-inline" style="width: 740px">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="reloadlst_submit" id="search">搜索
                </button>
                <button type="button" class="layui-btn layui-btn-primary" id="addMod">增加</button>
                <!--<button type="button" class="layui-btn" id="batchRev">批量提交</button>-->
                <button type="button" class="layui-btn layui-btn-radius" id="exports">下载模板</button>
                <form id="liu" enctype="multipart/form-data">
                <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" id="toLead">导入数据</button>
                </form>
                <button type="button" class="layui-btn layui-btn-danger layui-btn-radius" id="export">导出数据</button>

            </div>
        </div>
    </div>
<!--    <input type="hidden" id="kong">-->
</form>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="barDemo">
    {{#  if(d.isva == 10 || d.isva == 61){ }}
    <button class="layui-btn layui-btn-xs" lay-event="edit"> <!--<i class="layui-icon layui-icon-edit"></i>--> 编辑</button>
    <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
    <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="specification">说明书</button>
    <button class="layui-btn layui-btn-warm layui-btn-xs" lay-event="configuration">材料配置</button>
    <button class="layui-btn layui-btn-primary layui-btn-xs" lay-event="subAudit">提交审核</button>
    {{#  } else if(d.isva == 20){ }}
    <button disabled="disabled" class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="edit">编辑</button>
    <button disabled="disabled" class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="del">删除</button>
    <button disabled="disabled" class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="specification">说明书</button>
    <button disabled="disabled" class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="configuration">材料配置</button>
    <button disabled="disabled" class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="configuration">提交审核</button>
    {{#  } else if(d.isva == 60){ }}
    <button disabled="disabled" class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="edit">编辑</button>
    <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
    <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="specification">说明书</button>
    <button class="layui-btn layui-btn-xs" lay-event="configuration">材料配置</button>
    <button disabled="disabled" class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="subAudit">提交审核</button>
    {{#  } }}
    <button class="layui-btn layui-btn-xs" lay-event="audit">审核记录</button>

</script>


<script src="/res/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script type="text/html" id="tu">
    <img src="{{ d.images }}" alt="图片" width="50" height="30">
</script>
<script>
    var openIndex = null;
    var table = null;
    layui.use(['upload','table', 'form'], function () {
        table = layui.table;
        form = layui.form;
        upload = layui.upload;

        table.render({
            elem: '#test'
            , url: '/hqDrug/selectAllTwo'
            , title: '药品管理表'
            , cols: [[
                /*{type: 'checkbox', fixed: 'left',width:50}
                , */
                {type: 'numbers',title: '序号', width:50,fixed: 'left'}
                ,{field: 'drugName', title: '药品名称', width: 140, fixed: 'left', unresize: true, sort: true}
                , {field: 'typeName', title: '药品类型', width: 120}
                , {field: 'drugRetail', title: '零售价', width: 90}
                , {field: 'drugWho', title: '批发价', width: 90, sort: true}
                , {field: 'drugOut', title: '出库价', width: 90}
                , {field: 'isva', title: '药品状态', width: 100, templet: "#typeTpl"}
                , {field: 'images', title: '图片',width: 90, templet: "#tu"}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 398, fixed: 'right'}
            ]]
            , page: true
            ,done :function (res) {
                var vo = JSON.stringify(res.data);
                $("#excelDataVO").val(vo);
            }
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {  //删除药品
                layer.confirm('真的删除行么', function (index) {
                    var url = "/hqDrug/delete";
                    var dataMas = {drugId: data.drugId};
                    $.post(url, dataMas, function (bm) {
                        if (bm.status == 1) {
                            layer.msg(bm.message);
                            obj.del();
                            table.reload("test");
                        } else {
                            layer.msg(bm.message);
                        }
                    }, "json");
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {  //修改药品
                var drugId = data.drugId;
                openIndex = layer.open({
                    type: 2,
                    area: ['100%', '100%'], //宽高
                    title: "修改药品",
                    content: 'drugUp.html?id=' + drugId
                });
            } else if (obj.event === 'specification') {  //说明书
                var drugId = data.drugId;
                openIndex = layer.open({
                    type: 2,
                    area: ['100%', '100%'], //宽高
                    title: "药品说明书",
                    content: 'drugSpe.html?id=' + drugId
                });
            } else if (obj.event === 'configuration') {  //药品材料配置
                var drugId = data.drugId;
                var isva = data.isva;
                if (isva==60){
                    layer.open({
                        type: 2,
                        title: '配置材料',
                        shadeClose:true,//点击也能遮罩层关闭
                        skin: 'layui-layer-molv',//样式
                        shade: [0.8, '#393D49'] ,//显示遮罩
                        area : ['76%' , '75%'],//弹出框大小
                        maxmin: true, //开启最大化最小化按钮
                        shift:1,//弹出框动画效果
                        content: ["/ok-admin/pages/hqDrug/drugMatRead.html?id="+drugId,'on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                    });
                }else{
                    openIndex = layer.open({
                        type: 2,
                        area: ['100%', '100%'], //宽高
                        title: "药品材料",
                        content: 'drugMat.html?id=' + drugId
                    });
                }

            } else if (obj.event === 'subAudit') {  //提交审核
                console.info("提交审核");
                // var kon = $('#kong').val();
                // if (kon == 1) {
                    var url = "/hqDrug/updateReviewState";
                    var datas = {drugId: data.drugId}
                    $.post(url, datas, function (obj) {
                        console.info(obj.status);
                        if (obj.status == 20) {
                            layer.msg(obj.message);
                            table.reload("test");
                        } else {
                            layer.msg(obj.message);
                        }
                    }, "json")
                // } else {
                //     layer.msg("请配置材料");
                // }

            } else if (obj.event === 'audit') {  //查看审核记录
                console.info("查看审核记录");
                var drugId = data.drugId;
                openIndex = layer.open({
                    type: 2,
                    skin: 'layui-layer-molv',//样式
                    shade: [0.8, '#393D49'] ,//显示遮罩
                    area: ['85%', '85%'], //宽高
                    shadeClose:true,//点击也能遮罩层关闭
                    title: "查看审核记录",
                    content: '../audit/auditList.html?marketId=' + drugId
                });
            }
        });

        $("#search").on("click", function () {
            //执行重载
            table.reload('test', {
                where: {
                    'drugName': $("#drugName").val()
                },
                page: {
                    curr: 1
                }
            });
        });

        //指定允许上传的文件类型
        upload.render({
            elem: '#toLead'
            ,url: '/hqDrug/introExcel' //改成您自己的上传接口
            ,accept: 'file' //普通文件
            , exts: 'xlsx|xls' //只允许上传Excel文件
            ,done: function(res){
                layer.msg(res.message);
                table.reload("test");
            }
        });

    });
    $(function () {
        //增加
        $("#addMod").on("click", function () {
            console.info("进来");
            //页面层
            openIndex = layer.open({
                type: 2,
                area: ['100%', '100%'], //宽高
                title: "增加药品",
                content: 'drugUp.html'

            });
        });
        //导出数据
        $("#export").on("click", function () {
            //得到input的值
            var count = $("#excelDataVO").val();
           var url =  "/hqDrug/poiExcel?excelDataVO=" + count;
            location.href=url;
        });
        //下载模板
        $("#exports").on("click", function () {
            var url =  "/hqDrug/poiExcel";
            location.href=url;
        });
    })

    /**
     * 关闭弹出页面并提示
     */
    function closeOpen(msg) {
        layer.close(openIndex);
        layer.msg(msg, {time: 1100}, function () {
            table.reload("test");
        });
    }
    //接收父页面的值
    // function ChooseAdidValues(v) {
    //     if (v != "") {
    //         $('#kong').val(v);
    //     }
    // }
</script>
<script type="textml" id="typeTpl">
    {{#  if(d.isva == 10){ }}
    <span class="layui-btn layui-btn-danger layui-btn-xs">待审核</span>
    {{#  } else if(d.isva == 20){ }}
    <span class="layui-btn layui-btn-warm layui-btn-xs">审核中</span>
    {{#  } else if(d.isva == 60){ }}
    <span class="layui-btn layui-btn-xs">有效</span>
    {{#  } else if(d.isva == 61){ }}
    <span class="layui-btn layui-btn-danger layui-btn-xs">审核未通过</span>
    {{#  } }}
</script>
</body>
</html>